package com.yiya.service;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yiya.bean.DeviceType;
import com.yiya.bean.SysUser;
import com.yiya.mapper.DeviceTypeMapper;
import com.yiya.model.DeviceTypeModel;

@Service("deviceTypeService")
public class DeviceTypeService{
	@Autowired
	private DeviceTypeMapper deviceTypeMapper;

	public List<DeviceType> queryByList(DeviceTypeModel bean) {
		Integer rowCount = queryByCount(bean);
		bean.getPager().setRowCount(rowCount);
		List<DeviceType> deviceTypes = deviceTypeMapper.selectByModel(bean);
		return deviceTypes;
	}

	public int queryByCount(DeviceTypeModel bean) {
		return deviceTypeMapper.countByModel(bean);
	}
	
	public int add(DeviceType deviceType){
		return deviceTypeMapper.insert(deviceType);
	}
	
	public int Update(DeviceType deviceType){
		return deviceTypeMapper.updateByPrimaryKeySelective(deviceType);
	}
	
	public DeviceType queryById(Integer id){
		return deviceTypeMapper.selectByPrimaryKey(id);
	}
	
	public void delete(Integer[] ids,SysUser user){
		for(Integer id:ids){
			Date nowTime = new Date();
			DeviceType deviceType = deviceTypeMapper.selectByPrimaryKey(id);
			deviceType.setUpdateBy(user.getId());
			deviceType.setUpdateTime(nowTime);
			deviceType.setDelFlag(1);
			deviceTypeMapper.updateByPrimaryKeySelective(deviceType);
		}
	}
	
	/**
	 * 获取所有设备类型
	 * @return
	 */
	public List<DeviceType> getAllDeviceType(){
		return deviceTypeMapper.selectAll();
	}
}
